package com.hs.telepass;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;

import com.baidu.android.pushservice.PushMessageReceiver;
import com.hs.telepass.manager.PreferencesManager;
import com.hs.telepass.ui.WebActivity;
import com.hs.telepass.utils.PreferencesUtil;
import com.hs.telepass.utils.ToastUtil;

import java.util.List;

/**
 * Created by dasunsy on 2015/7/7 0007.
 */
public class PushReceiver extends PushMessageReceiver {
    @Override
    public void onBind(Context context, int errorCode, String appid,
                       String userId, String channelId, String requestId) {
        String responseString = "onBind errorCode=" + errorCode + " appid="
                + appid + " userId=" + userId + " channelId=" + channelId
                + " requestId=" + requestId;
        Log.d(TAG, responseString);

        if(0 == errorCode){
            PreferencesManager.getInstance().setToken(channelId);

        }
    }

    @Override
    public void onUnbind(Context context, int i, String s) {

    }

    @Override
    public void onSetTags(Context context, int i, List<String> strings, List<String> strings2, String s) {

    }

    @Override
    public void onDelTags(Context context, int i, List<String> strings, List<String> strings2, String s) {

    }

    @Override
    public void onListTags(Context context, int i, List<String> strings, String s) {

    }

    @Override
    public void onMessage(Context context, String s, String s2) {

    }

    @Override
    public void onNotificationClicked(Context context, String title, String description, String customContentString) {
        String url = "http://weben.open.com.mo/ClientMessage/device_msgs_list?store_id="
                + PreferencesManager.getInstance().getStoreId()  + "&token="
                + PreferencesManager.getInstance().getToken();

        Intent intent=new Intent();
        intent.setAction("android.intent.action.VIEW");
        Uri CONTENT_URI_BROWSERS = Uri.parse(url);
        intent.setData(CONTENT_URI_BROWSERS);
        intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        context.startActivity(intent);

    }

    @Override
    public void onNotificationArrived(Context context, String s, String s2, String s3) {

    }
}
